package com.example.prototype;

import java.util.ArrayList;
import java.util.List;

public class Prototype implements Cloneable {
    private int id;
    private String name;
    private List<String> tags;

    @Override
    public Prototype clone() {
        try {
            // 浅拷贝
            // 要实现 Cloneable 接口
            Prototype prototype =  (Prototype) super.clone();
            // 深拷贝
            prototype.tags = new ArrayList<>(this.tags);
            return prototype;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setTags(List<String> tags) {
        this.tags = tags;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public List<String> getTags() {
        return tags;
    }

    public Prototype(int id, String name, List<String> tags) {
        this.id = id;
        this.name = name;
        this.tags = tags;
    }

    @Override
    public String toString() {
        return "Prototype{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", tags=" + tags +
                '}';
    }
}
